package com.lxm.controller;


import com.lxm.dto.AddressDTO;
import com.lxm.dto.Result;
import com.lxm.service.AddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 地址表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-10-02
 */
@Tag(name = "地址管理")
@RestController
@RequestMapping("/user/address")
public class AddressController {
    @Resource
    AddressService addressService;

    @Operation(summary = "添加地址")
    @PostMapping("/add")
    public Result add(@RequestBody AddressDTO address) {
        return addressService.add(address);
    }

    // 地址一般不会有太多，所以直接返回全部数据前端分页即可
    @Operation(summary = "获取地址列表")
    @GetMapping("/list")
    public Result list() {
        return addressService.listByUserId();
    }

    @Operation(summary = "删除地址")
    @DeleteMapping("/delete/{id}")
    public Result deleteAddress(@PathVariable Long id) {
        return addressService.deleteAddress(id);
    }

    @Operation(summary = "修改地址")
    @PutMapping("/update")
    public Result update(@RequestBody AddressDTO address) {
        return addressService.updateAddress(address);
    }

}

